#!/bin/bash

pid=$(ps -ef | grep datalife-0.0.1-SNAPSHOT.jar | grep -v grep | awk -F " " '{print $2}')

if [ -n "$pid" ]
then
  kill $pid
fi

git pull --rebase origin master

mvn clean package -Dmaven.test.skip=true -P=production

if [ ! -d ~/logs ];
then
  mkdir ~/logs
fi

time=$(date "+%Y-%m-%d_%H:%M:%S")

nohup java -Dspring.profiles.active=production -jar ./target/datalife-0.0.1-SNAPSHOT.jar > ~/logs/server_${time}.log 2>&1 &

echo "------------------------------------------------------------ restart success ------------------------------------------------------------"
